/**
 * @Author: wangliuyang
 * @Date: 2021/9/5 13:08
 * @Description:922. 按奇偶排序数组 II
 */
public class Solution_922 {
    public int[] sortArrayByParityII(int[] nums) {
        int one = 0;
        int two = 1;
        while (one < nums.length && two < nums.length){
            if ((nums[one] & 1) == 0){
                one += 2;
            }else {
                swap(nums,one,two);
                two += 2;
            }
        }
        return nums;
    }
    public void swap(int[] nums,int one, int two){
        if (nums == null || nums.length == 0) {
            return;
        }
        nums[one] = nums[one] ^ nums[two];
        nums[two] = nums[one] ^ nums[two];
        nums[one] = nums[one] ^ nums[two];
    }
}
